package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dto.ProductPageDTO;
import com.sc.nft.entity.DigitalCollection;
import com.sc.nft.entity.MallActivity;
import com.sc.nft.entity.vo.SaasTaskDetailsCollectionVO;
import com.sc.nft.enums.ApprovalStatusEnum;
import com.sc.nft.enums.MallChannelEnum;
import com.sc.nft.enums.ProductTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MallProduct;
import com.sc.nft.mapper.MallProductMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * IP商城商品表(sc_mall_product)数据DAO
 *
 * @author zxy
 * @since 2023-05-10 16:59:01
 * @description IP商城
 */
@Slf4j
@Repository
public class MallProductDao extends ServiceImpl<MallProductMapper, MallProduct> {
    public IPage<ProductPageDTO> getProductPage(Long categoryId,ProductTypeEnum type, ApprovalStatusEnum approvalStatus, Long daoId, String name, Page page,Long supplierId,String supplierName) {
        return baseMapper.getProductPage(page,categoryId,type!=null?type.getCode():null, approvalStatus!=null?approvalStatus.getCode():null, daoId, name ,supplierId,supplierName);
    }

    public List<MallProduct> getByIds(List<Long> linkIds) {
        LambdaQueryWrapper<MallProduct> wrapper = new LambdaQueryWrapper<MallProduct>();
        wrapper.in(MallProduct::getId,linkIds);
        return list(wrapper);
    }

    public List<MallProduct> simpleList(String productName) {
        LambdaQueryWrapper<MallProduct> wrapper = new LambdaQueryWrapper<MallProduct>();
        wrapper.select(MallProduct::getId,MallProduct::getProductName);
        wrapper.like(MallProduct::getProductName,productName);
        return list(wrapper);
    }
    public MallProduct getByProductCodeAndChannel(String productCode, MallChannelEnum channel){
        return lambdaQuery().eq(MallProduct::getProductCode,productCode).eq(MallProduct::getProductChannel,channel).one();
    }

    public Integer getCountByCategoryId(Long id) {
        return lambdaQuery().eq(MallProduct::getCategoryId,id).count();
    }
    /**
     * 根据ids获取对应的藏品信息
     * @param ids
     * @return
     */
    public List<SaasTaskDetailsCollectionVO> getMallProductSimplenessByIds(List<Long> ids) {
        return baseMapper.getMallProductSimplenessByIds(ids);
    }

    public boolean updateDao(Long id, Long daoId) {
        UpdateWrapper<MallProduct> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", id);
        wrapper.set("dao_id", daoId);
        return update(new MallProduct(), wrapper);
    }
}